/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itschapala.dsw2.biblioteca8a.dao;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import mx.itschapala.dsw2.biblioteca8a.modelo.Autor;

/**
 *
 * @author Lindemann
 */
@Stateless
public class AutorDao extends AbstractDao<Autor> implements AutorDaoLocal {
    @PersistenceContext(unitName = "Biblioteca8A-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public AutorDao() {
        super(Autor.class);
    }

    @Override
    public boolean findDuplicity(Autor author) {
        //seleccionar consulta
        Query q= em.createNamedQuery("Autor.findDuplicity");
        //poner parametros
        q.setParameter("nombre",author.getNombre());
        q.setParameter("apellidoPaterno",author.getApellidoPaterno());
        q.setParameter("apellidoMaterno",author.getApellidoMaterno());
        //ejecutar
        return !q.getResultList().isEmpty();
    }

}
